import java.sql.*;
import java.util.ResourceBundle;

public class JdbcDemo07 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1、注册驱动
        Class.forName("com.mysql.jdbc.Driver");// 反射
        ResourceBundle rb = ResourceBundle.getBundle("jdbc");
        String url = rb.getString("url");
        String user = rb.getString("user");
        String password = rb.getString("password");
        Connection connection = DriverManager.getConnection(url, user, password);
        // 2、开启事务,关闭自动提交机制
        connection.setAutoCommit(false);
        String sql = "update student set birth='1999' where id = 902";
        String sql1 = "update student set birth='1999' where id = 903";
        Statement statement = connection.createStatement();
        int i1 = statement.executeUpdate(sql);
        int i = statement.executeUpdate(sql1);
        if (i1 == 1 && i == 1) {
            connection.commit();// 手动提交
        } else {
            connection.rollback();// 回滚
        }


    }
}
